<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>销售订单相关的退货订单记录</title>
<script type="text/javascript">
    var saleReturnedId;
    Ext.onReady(function () {
        var returnedForSaleDS = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model:'SaleReturnedModel',
            proxy:{
                type:'ajax',
                extraParams:{sale_order_id:'<%=params[:id]%>'},
                url:'/sale_returned/getSaleReturnedsBySaleOrderId',
                reader:{
                    type:'json',
                    root:'root',
                    totalProperty:'totalProperty'// 数据集记录总数
                }
            },
            autoLoad:true
        });


        //生成要订单的产品的Grid
        var returnedForSaleGrid = Ext.create('Ext.grid.Panel', {
            title:'退货订单列表',
            store:returnedForSaleDS,
            columns:[Ext.create('Ext.grid.RowNumberer'), {
                header:'DB',
                dataIndex:'id',
                width:50
            }, {
                header:'退货订单号',
                dataIndex:'order_number',
                width:130
            }, {
                header:'退货日期',
                dataIndex:'action_date',
                renderer:Ext.util.Format.dateRenderer('Y-m-d'), width:80
            }, {
                header:'审批状态',
                dataIndex:'auditing_status',
                width:65,
                renderer:auditingStatusRender
            }, {
                header:'操作员',
                dataIndex:'employee_name',
                width:60
            }, {
                header:'部门',
                dataIndex:'department_name',
                width:80
            }, {
                header:'订单状态',
                dataIndex:'deal_with_status',
                renderer:dealWithStatusRender,
                width:60
            }, {
                header:'生成日期',
                dataIndex:'created_at',
                renderer:Ext.util.Format.dateRenderer('Y-m-d H:i'), width:115
            }, {
                header:'修改日期',
                dataIndex:'updated_at',
                renderer:Ext.util.Format.dateRenderer('Y-m-d H:i'), width:115
            }],
            loadMask:true,
            width:980,
            height:270,
            frame:true
        });


        returnedForSaleGrid.on('itemdblclick', function (gridPanel, record, item, index, e, options) {
            saleReturnedId = returnedForSaleDS.getAt(index).get('id');
            var saleOrderNumber = returnedForSaleDS.getAt(index).get('order_number');
            //returnedForSaleDS.load();
            saleReturnedDetailDS.removeAll();
            saleReturnedDetailDS.load({params:{'sale_returned_id':saleReturnedId}});
            saleReturnedDetailGrid.setTitle("退货订单：" + saleOrderNumber + "，的详细信息");
        });


        var saleReturnedDetailDS = Ext.create('Ext.data.Store', {
            //autoDestroy : true,
            model:'SaleReturnedDetailModel',
            proxy:{
                type:'ajax',
                extraParams:{sale_returned_id:'0'},
                url:'/sale_returned/getSaleReturnedDetailsById',
                reader:{
                    type:'json',
                    root:'root',
                    totalProperty:'totalProperty'// 数据集记录总数
                }
            }
        });

        //--------------------------退货订单详细，双击后可显示数据----------------

        //生成销售订单详细表的Grid的CM
        //生成要订单的产品的Grid
        var saleReturnedDetailGrid = Ext.create('Ext.grid.Panel', {
            title:'退货订单详细列表',
            store:saleReturnedDetailDS,
            columns:[Ext.create('Ext.grid.RowNumberer'), {
                header:'DB',
                dataIndex:'id',
                width:50
            }, {
                header:'产品名称',
                dataIndex:'product_name',
                width:230
            }, {
                header:'编号', dataIndex:'product_number', width:100
            }, {
                header:'规格',
                dataIndex:'product_spec',
                width:80
            }, {
                header:'数量',
                dataIndex:'quantity',
                align:'right',
                width:60
            }, {
                header:'单价',
                dataIndex:'unit_price',
                renderer:Ext.util.Format.numberRenderer('0,000.00'),
                align:'right',
                width:70
            }, {
                header:'折扣',
                dataIndex:'discount',
                renderer:Ext.util.Format.numberRenderer('0,000.000000'),
                width:70
            }, {
                header:'总价',
                dataIndex:'amount',
                align:'right',
                renderer:Ext.util.Format.numberRenderer('0,000.00'),
                width:80
            }, {
                header:'套装或单品',
                dataIndex:'is_suit',
                width:70
            }, {
                header:'备注',
                dataIndex:'description',
                width:170
            }],
            loadMask:true,
            width:980,
            height:295,
            frame:true
            //title: '进货品种列表',
            //plain:true,
            //plugins: checkColumn,
        });
        //总的panel
        var workbenchPanel = Ext.create('Ext.form.Panel', {
            width:990,
            height:590,
            frame:false,
            layout:{type:'table', columns:1},
            items:[returnedForSaleGrid, saleReturnedDetailGrid]
        });
        workbenchPanel.render("returned_for_sale_workbench_panel");
    })
</script>
</head>
<body>
<div id="returned_for_sale_workbench_panel"></div>
</body>
</html>